﻿using System;
using System.Collections.Concurrent;

namespace Longbow.Net
{
    /// <summary>
    /// Scoket 服务器端接口
    /// </summary>
    public interface ISocketServer : IDisposable
    {
        /// <summary>
        /// 获得 SocketServerStatus 状态
        /// </summary>
        SocketServerStatus Status { get; }

        /// <summary>
        /// 获得 异常错误信息
        /// </summary>
        Exception Exception { get; }

        /// <summary>
        /// 获得 当前已建立连接的客户端集合
        /// </summary>
        ConcurrentDictionary<string, ISocketClient> Clients { get; }

        /// <summary>
        /// Socket Server 开始侦听方法
        /// </summary>
        /// <param name="acceptCallback">接收客户端回调方法</param>
        /// <param name="receiveCallback">接收数据回调方法</param>
        /// <param name="configure">客户端连接配置项回调方法</param>
        /// <returns>成功时返回真</returns>
        bool Start(Action<ISocketClient> acceptCallback, Action<ISocketClient, byte[]> receiveCallback, Action<SocketConnectOptions> configure = null);

        /// <summary>
        /// Socket Server 停止侦听方法
        /// </summary>
        void Stop();
    }
}
